#include <REGX52.H>
#include "delay.h"
#include "LCD1602.h"
#include "MatrixKey.h"
 


void main()
{
	unsigned char keynum = 0;
	unsigned int password = 0;
	unsigned int count = 0;
	LCD_Init();
	LCD_ShowString(1,1,"Password:");
	
	while(1)
	{
		keynum = MatrixKey();
		if(keynum)
		{
			if(keynum<=10 && count<4)
			{
				password*=10;
				password+=keynum%10;
				count++;
			}
			LCD_ShowNum(2,1,password,4);
			if( keynum == 11)
			{
				if(password == 2345)
				{
					LCD_ShowString(1,14,"ok ");
					password =0;
					count = 0;
					LCD_ShowNum(2,1,password,4);
				}
				else
				{
					LCD_ShowString(1,14,"err");
					password =0;
					count = 0;
					LCD_ShowNum(2,1,password,4);
				}				
			}
			if( keynum == 12)
			{
				password =0;
				count = 0;
				LCD_ShowNum(2,1,password,4);
			}
		}
	}
}